<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>APP</title>
    <link rel="stylesheet" href="../../css/api.css" />
    <link rel="stylesheet" href="../../css/aui.css" />
    <link rel="stylesheet" href="../../css/aui-flex.css" />
    <link rel="stylesheet" href="../../css/list.css" />
</head>
<body>
  <header class="aui-bar aui-bar-nav aui-bar-light" style="background-color: #ebeced;">
      <div class="aui-pull-left aui-btn" onclick="closeWin();">
          <span class="aui-iconfont aui-icon-left aui-text-default"></span>
      </div>
      <div class="aui-title" style="left:2rem; right: 0.5rem;">
          <div class="aui-searchbar">
              <div class="aui-searchbar-input aui-border-radius">
                  <i class="aui-iconfont aui-icon-search"></i>
                  <input type="search" placeholder="请输入搜索内容" id="search-input">
                  <div class="aui-searchbar-clear-btn">
                      <i class="aui-iconfont aui-icon-close"></i>
                  </div>
              </div>
              <div class="aui-searchbar-btn" tapmode>取消</div>
          </div>
      </div>
  </header>
  <nav>
    <ul class="aui-flex-col aui-bg-white aui-border-b">
      <li class="aui-flex-item-4 aui-font-size-14 aui-flex-col aui-flex-center aui-flex-middle aui-border-r aui-padded-t-10 aui-padded-b-10">
          <span class="aui-margin-r-5">全太原</span>
          <span class="aui-font-size-12">
            <i class="aui-iconfont aui-icon-down"></i>
          </span>
      </li>
      <li class="aui-flex-item-4 aui-font-size-14 aui-flex-col aui-flex-center aui-flex-middle aui-border-r aui-padded-t-10 aui-padded-b-10">
          <span class="aui-margin-r-5">公司</span>
          <span class="aui-font-size-12">
            <i class="aui-iconfont aui-icon-down"></i>
          </span>
      </li>
      <li class="aui-flex-item-4 aui-font-size-14 aui-flex-col aui-flex-center aui-flex-middle aui-padded-t-10 aui-padded-b-10">
          <span class="aui-margin-r-5">会员</span>
          <span class="aui-font-size-12">
            <i class="aui-iconfont aui-icon-down"></i>
          </span>
      </li>
    </ul>
  </nav>

</body>
<script src="../../script/api.js"></script>
<script src="../../script/zepto.js"></script>
<script src="../../script/common.js"></script>
<script>
	function getBType(t){
		if(t == 1){
			$('#stype').html("家居生活");
		}
		if(t == 2){
			$('#stype').html("电子器械");
		}
		if(t == 3){
			$('#stype').html("装潢家具");
		}
		if(t == 4){
			$('#stype').html("食品保健");
		}
		if(t == 5){
			$('#stype').html("商业服务");
		}
		if(t == 6){
			$('#stype').html("固定资产");
		}
		if(t == 7){
			$('#stype').html("书画艺术");
		}
		$('#stype').html("所有分类");
	}
	$('.address').hide();
	var sv = 0;
	var pn = 1;
	var total = 1;

	var url=location.search;
	var request = new Object();
	if(url.indexOf("?")!=-1){
	 　　var str = url.substr(1);　//去掉?号
		strs = str.split("&");
		for(var i=0;i<strs.length;i++){
			request[strs[i].split("=")[0]]=unescape(strs[ i].split("=")[1]);
		}
	}

	var type = '';
  var name = '';
  var bType = '';
	// var name = request['key']==undefined?'':decodeURI(request['key']);
	var demand = 0;
	var uType = 0;
	var uLevel = -1;
	var area = 0;

  apiready = function(){
    bType = api.pageParam.bType || '0';
    type = api.pageParam.type || '0';
    name = api.pageParam.key ? decodeURI(request['key']) : '';
    /*
    $('.pull-down').click(function(){

    $(this).addClass("active").siblings().removeClass("active");
     for (var i = 0; i < 2; i++) {
              if (i == index) {
                  $api.addCls(aFooterList[index],'active');
              } else{
                  $api.removeCls(aFooterList[i],'active');
              }
        };

    var elem=$(this).children();
    if(elem.length>1 && elem.is(':hidden')){
      $(".multiple>ul>li ul").show();
    }else{
        $(".multiple>ul>li ul").hide()
    }
    })*/
  }

	if(bType != '0'){
		getBType(bType);
	}

	var areaList = [];
	var currProv = 0;
	var typeList = [];
	var currType = 0;
	var currDemand = 0;

	$.ajax({
		url : "http://www.aiyi5.com/getGoodsTypeForList",
		type : "POST",
		async : false,
		dataType: 'json',
		error: function(errorMsg) {

		},
		success: function(data) {
			typeList = data;
			$('#type').empty();
			$('#demand').empty();
			$.each(data, function(n, v) {
				if(currType == 0){
					currType = v.id;
					currDemand = v.id;
				}
				$('#type').append('<li onclick="setType(\'' + v.id + '\')"><span>' + v.text + '</span></li>');
				$('#demand').append('<li onclick="setDemand(\'' + v.id + '\')"><span>' + v.text + '</span></li>');
			});
		}
	});

	function setType(id){
		$('#subType').empty();
		currType = id;
		$.each(typeList, function(n, v) {
			if(v.id == id){
				$.each(v.nodes, function(n1, v1) {
					$('#subType').append('<li><span onclick="setSubType(\'' + v1.id + '\', \'' + v1.text + '\')">' + v1.text + '</span></li>');
				});
			}
		});
	}
	setType(currType);

	function setSubType(id, text){
		type = id;
		pn = 1;
		$('#stype').html(text);
		bType = 0;
		query();
		$('#types').hide();
	}

	function setDemand(id){
		$('#subDemand').empty();
		currDemand = id;
		$.each(typeList, function(n, v) {
			if(v.id == id){
				$.each(v.nodes, function(n1, v1) {
					$('#subDemand').append('<li><span onclick="setSubDemand(\'' + v1.id + '\', \'' + v1.text + '\')">' + v1.text + '</span></li>');
				});
			}
		});
	}
	setDemand(currDemand);

	function setSubDemand(id, text){
		type = id;
		pn = 1;
		$('#sdemand').html(text);
		query();
		$('#demands').hide();
	}

  // 获取城市区域
  function getAreas() {
    showProgress();
    $.ajax({
  		url : "http://www.aiyi5.com/getArea",
  		type : "POST",
  		async : false,
  		dataType: 'json',
  		error : function(errorMsg) {
        hideProgress();
        toast(errorMsg);
  		},
  		success : function(data) {
  			areaList = data;
  			$('#prov').empty();
  			$.each(data, function(index, item) {
  				if(currProv == 0){
  					currProv = item.code;
  				}
  				if(v.parent == '0'){
  					$('#prov').append('<li onclick="setProv(\'' + item.code + '\')"><span>' + item.name + '</span></li>');
  				}
  			});
        hideProgress();
  		}
  	});
  }

	function setProv(code){
		$('#city').empty();
		currProv = code;
		$.each(areaList, function(index, item) {
			if(item.parent == code){
				$('#city').append('<li><span onclick="setCity(\'' + item.code + '\', \'' + item.name + '\')">' + item.name + '</span></li>');
			}
		});
	}
	setProv(currProv);

	function setCity(code, name){
		area = code;
		pn = 1;
		$('#scity').html(name);
		query();
		$('#area').hide();
	}

	function openOpt(id){
		$('.address').hide();
		if(sv == 0){
			$('#' + id).show();
			sv = 1;
			return;
		} else{
			sv = 0;
		}
	}

	function query(){
		var d = {
			type: type,
			demand: demand,
			uType: uType,
			uLevel: uLevel,
			area: area,
			name: name,
			bType: bType,
			pageNo: pn
		}
		$.ajax({
			url : "http://www.aiyi5.com/getGoodsList",
			type : "POST",
			async : false,
			data: d,
			dataType: 'json',
			error : function(errorMsg) {

			},
			success : function(data) {
				$('#goods').empty();
				$.each(data.t,function(n, v) {
					var temp = '<div class="more_unit sp1_2" tapmode="tap-active" onclick="openGoods(' + v.id + ')">';
                    temp += '<div class="img_box"><img src="http://www.aiyi5.com/resource/goods/' + v.img + '" alt=""></div>';
                    temp += '<div class="reload_detail">';
                    temp += '<p class="reload_p1">' + v.name + '</p>';
                    temp += '<p class="reload_p2">' + !v.level?'非会员':v.level + '</p>';
                    temp += '<p class="reload_p3">数量：<span>' + v.amount + '</span></p>';
                    temp += '<p class="reload_p4">价格：<span>' + v.val + '</span></p></div></div>';
                    $('#goods').append(temp);
				});
				total = data.total / 40 + 1;
				//setPage();
			}
		});
	}

	query();



		$(".pull-down ul li").click(function(){
			$(this).addClass("active").siblings().removeClass("active");
			$(this).find("i").show();
		})

		$("#main").scroll(function(){
			 t = $("#main").scrollTop();
			 if(t>10){
			 	$(".multiple>ul>li ul").hide()
			 }
		})

    // apiready();
    /*$api.dom('#id');
     $api.domAll('.class');
     * */
</script>
</html>
